<?php
/**
 * User:姜亮
 * Date: 2018/8/31 ;Time: 15:44;
 * 常用方法
 */

namespace app\admin\controller;

use think\Controller;
use Lib\SendMessage;
use think\Config;
use think\captcha\Captcha;
class Sys extends Controller
{
    /**
     * @return array|mixed
     * 容联云发送短信
     */
    public function message()
    {
        //标识
        $tag = input('phoneNumberTag');
        if (empty($tag)) {
            return $this->fetch();
        } else {
            $form = input('post.');
            $sendMessage = new SendMessage();
            $result = $sendMessage->sendTemplateSMS($form['phoneNumber'], array($form['messageValide'], $form['valideTime']), $form['templateId']);
            if ($result == 'success') {
                return xmall_msg(200, 'ok');
            } else {
                return xmall_msg(201, 'fail');
            }
        }
    }
    /**
     * 图片验证码
     */
    public function sysCaptcha(){
        return $this->fetch('sysCaptcha');
    }
    /**
     * 邮箱校验
     */
    public function email(){
        //标识
        $tag = input('emailTag');
        if (empty($tag)) {
            return $this->fetch();
        } else {
            $form = input('post.');
            $res=send_mail($form['email'], $form['name'], $form['subject'], $form['content']);
            if ($res) {
                return xmall_msg(200, 'ok');
            } else {
                return xmall_msg(201, 'fail');
            }
        }
    }
}